﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NCT.MRS.DataAccessLayer
{
    public sealed class UnitOfWork : IUnitOfWork, IDisposable
    {
        
        public UnitOfWork(IAppContext context)
        {
            _context = context;
        }

        private readonly IAppContext _context;

        public void Commit()
        {
            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (DbUpdateException exx)
            {
                throw exx;
            }
            catch (Exception exxx)
            {
                throw exxx;
            }
        }

        public void Dispose()
        {
            _context.Dispose();
        }
    }
}
